package com.xkdx.guangguang.fragment.user;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.module.statics.IConstants;

public class UserBindQQModule extends AbsModule {

	JSONObject values;
	private Context context;
	private UserSharePrefence user_sp;
	public BindQQDetailInfo qqDetailinfo;
	public BindQQUser bindQQUser;
	JSONArray jsonArray;
	JSONObject jsonObj;

	public UserBindQQModule(Context context) {
		this.context = context;
	}

	@Override
	public void parseData() throws Exception {

		try {
			qqDetailinfo = new BindQQDetailInfo();
			user_sp = new UserSharePrefence(context, IConstants.SP_USER);
			bindQQUser = new BindQQUser();
			jsonArray = (JSONArray) result;
			jsonObj = (JSONObject) jsonArray.get(0);

			bindQQUser = parserBindUserRgist(jsonObj.getJSONObject("Content"));
		} catch (Exception e) {

			throw e;
		}

	}

	private BindQQUser parserBindUserRgist(JSONObject bind) {
		try {
			JSONObject stut = (JSONObject) bind.get("Result");
			JSONObject detail = (JSONObject) stut.getJSONObject("DetailInfo");
			qqDetailinfo.setUserID(detail.getString("UserID"));
			qqDetailinfo.setSex(detail.getString("Sex"));
			qqDetailinfo.setQQNickName(detail.getString("QQNickName"));
			qqDetailinfo.setQQToken(detail.getString("QQToken"));
			qqDetailinfo.setQQExpireTime(detail.getString("QQExpireTime"));
			qqDetailinfo.setQQOpenID(detail.getString("QQOpenID"));

			bindQQUser.setErrorCode(stut.getString("ErrorCode"));
			bindQQUser.setMessage(stut.getString("Message"));
			bindQQUser.setType(stut.getString("Type"));
			bindQQUser.setStatus(stut.getString("Status"));
			bindQQUser.setBindQQDetailInfo(qqDetailinfo);

			// 设置令牌
			if ("Success".equals(stut.getString("Status"))) {
				user_sp.setUserID(detail.getString("UserID"));
				user_sp.setUserSex(detail.getString("Sex"));
				user_sp.setQQNickName(detail.getString("QQNickName"));
				user_sp.setQQToken(detail.getString("QQToken"));
				user_sp.setQQExpireTime(detail.getString("QQExpireTime"));
				user_sp.setQQOpenID(detail.getString("QQOpenID"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return bindQQUser;
	}

	public class BindQQUser {
		private String Type;
		private String Status;
		private String ErrorCode;
		private String Message;
		private BindQQDetailInfo bindQQDetailInfo;

		public String getType() {
			return Type;
		}

		public void setType(String type) {
			Type = type;
		}

		public String getStatus() {
			return Status;
		}

		public void setStatus(String status) {
			Status = status;
		}

		public String getErrorCode() {
			return ErrorCode;
		}

		public void setErrorCode(String errorCode) {
			ErrorCode = errorCode;
		}

		public String getMessage() {
			return Message;
		}

		public void setMessage(String message) {
			Message = message;
		}

		public BindQQDetailInfo getBindQQDetailInfo() {
			return bindQQDetailInfo;
		}

		public void setBindQQDetailInfo(BindQQDetailInfo bindQQDetailInfo) {
			this.bindQQDetailInfo = bindQQDetailInfo;
		}
	}

	public class BindQQDetailInfo {
		private String UserID;
		private String Sex;
		private String QQOpenID;
		private String QQNickName;
		private String QQToken;
		private String QQExpireTime;

		public String getUserID() {
			return UserID;
		}

		public void setUserID(String userID) {
			UserID = userID;
		}

		public String getSex() {
			return Sex;
		}

		public void setSex(String sex) {
			Sex = sex;
		}

		public String getQQOpenID() {
			return QQOpenID;
		}

		public void setQQOpenID(String qQOpenID) {
			QQOpenID = qQOpenID;
		}

		public String getQQNickName() {
			return QQNickName;
		}

		public void setQQNickName(String qQNickName) {
			QQNickName = qQNickName;
		}

		public String getQQToken() {
			return QQToken;
		}

		public void setQQToken(String qQToken) {
			QQToken = qQToken;
		}

		public void setQQExpireTime(String qQExpireTime) {
			QQExpireTime = qQExpireTime;
		}

		public String getQQExpireTime() {
			return QQExpireTime;
		}

	}
}